from common.config_parse import YamlConfig
from common.MySQL import MySQL
import redis
from common.const import cur_env
from common.log import Log


class DbCreator:
    def __init__(self, tag=cur_env):
        # self.tag = tag
        self.config = YamlConfig.get_rainbow_config(tag)  # 某个节点下面所有的

    def mysql_creator(self, node="mysql", data_type=2):
        mysql_info = self.config.get(node)
        # mysql_info = self.config.node#错误
        mysql_obj = MySQL(mysql_info, data_type)
        return mysql_obj

    def redis_creator(self, node="redis"):
        redis_info = self.config.get(node)
        Log.debug("redis配置：{}",redis_info)
        r = redis.Redis(**redis_info,decode_responses=True)
        return r


if __name__ == '__main__':
    db_creator = DbCreator("test1")
    mysql = db_creator.mysql_creator()
    ret = mysql.fetchone("select * from fmz_user limit 1;")
    print(ret)
